var ctx = $("#ctx").val();
$(function () {
    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            $(".login-button").trigger("click");
        }
    });
    $(".login-button").click(function () {
        var inputs = $("#loginForm input");
        var login = true;
        $.each(inputs, function (index, input) {
            if ($(input).val() == "") {
                login = false;
            }
        });
        if (login == false) {
            mdui.snackbar({
                message: "各项不为空",
                position: "top"
            });
        } else {
            $.ajax({
                url: ctx + "/user/login",
                type: "POST",
                data: $("#loginForm").serialize(),
                success: function (data) {
                    if (data.code == 0) {
                        mdui.snackbar({
                            message: "登录成功",
                            position: "top"
                        });
                        setTimeout(function () {
                            location.href = ctx + "/";
                        }, 1000)
                    } else {
                        mdui.snackbar({
                            message: data.msg,
                            position: "top"
                        });
                    }
                }
            });
        }
    });
});